Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UseIgnoreDisconnections helper #63

Merged
merged 1 commit into from
Aug 19, 2024
Merged

Conversation

Shane32
Copy link
Owner

@Shane32 Shane32 commented Aug 19, 2024

This PR adds a helper method to consume OCEs when the client disconnects unexpectedly, which is common when the client is a web browser with an open WebSocket connection to the server. ASP.NET Core does not consume these OCEs by default, and since GraphQL over WebSockets can perform any query or mutation that a GET/POST can, it seems that there is no reason why an OCE should be consumed for a WebSocket connection and not for any other connection. Futher, for server-to-server communications, it may be desired to log these exceptions. As such, the default behavior has not been changed. Note that graceful teardown of the WebSocket connection (per WebSocket spec) does not produce an OCE.

See added readme text:

When hosting a WebSockets endpoint, it may be common for clients to simply disconnect rather than gracefully terminating the connection -- most specifically when the client is a web browser. If you log exceptions, you may notice an OperationCanceledException logged any time this occurs.

In some scenarios you may wish to log these exceptions -- for instance, when the GraphQL endpoint is used in server-to-server communications -- but if you wish to ignore these exceptions, simply call app.UseIgnoreDisconnections(); immediately after any exception handling or logging configuration calls. This will consume any OperationCanceledExceptions when HttpContext.RequestAborted is signaled -- for a WebSocket request or any other request.

@Shane32 Shane32 self-assigned this Aug 19, 2024
Copy link

Coverage Report

Totals Coverage
Statements: 96.99% ( 1834 / 1891 )
Methods: 81.98% ( 282 / 344 )

@Shane32 Shane32 merged commit c3cd223 into master Aug 19, 2024
5 checks passed
@Shane32 Shane32 deleted the ignore_disconnections branch August 19, 2024 01:23
@coveralls
Copy link

Pull Request Test Coverage Report for Build 10445421185

Details

  • 10 of 10 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 94.541%

Totals Coverage Status
Change from base Build 10445398764: 0.02%
Covered Lines: 1834
Relevant Lines: 1891

💛 - Coveralls

@Shane32 Shane32 added this to the 5.3.0 milestone Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants